<?php

// test script for dbClients.php

include_once(dirname(__FILE__) . '/../domain/Client.php');
include_once('checkRoutines.inc');

define("PHONE", "233-333-4545");
define("SSN","444-44-4444");
define("ID","Gabrielle2333334545");

echo 'testing dbClients.php</br>';
testAddClient();
testRetrieveClient();
testRetrieve_client_by_name();
//testGetOnlyThose_dbClients();
testRetrieve_client_by_status();
testRetrieve_client_by_ssn();

//testGetall_dbPersons();
//testGetall_volunteer_names();
//testGetall_type();
//testGetall_available();
echo("testdbClients complete</br>");

// tests the add_client() function in dbClients.php
function testAddClient() {
    $client = new Client("Gabrielle", "Booth", SSN, "14 Way St", "Harpswell, ME, 04079", PHONE, "212-899-3434", "Sam Booth", "212-455-9999","Jan 5, 2005",9,"meds","notes");

    echo 'will test add_client </br>';
    $result = add_client($client);
    echo 'result is ' . $result.'</br>';
    if ($result)
        echo "client inserted </br>";
    else
        echo "client not inserted</br>";

   $res = remove_client(ID);
    if ($res == null)
        echo 'Retrieve failed</br>';
}

// tests the retrieve_client() function in dbClients.php
function testRetrieveClient() {
    
  $client = new Client("Gabrielle", "Booth", SSN, "14 Way St", "Harpswell, ME, 04079", PHONE, "212-899-3434", "Sam Booth", "212-455-9999","Jan 5, 2005",9,"meds","notes");
    echo 'will test retrieve_client </br>';
    $result = add_client($client);
    echo 'result is ' . $result.'</br>';
    if ($result)
        echo "client inserted </br>";
    else
        echo "client not inserted</br>";


    $client = retrieve_client(ID);
    if ($client == null)
        echo 'Retrieve failed</br>';
    else {
        checkEquals($client->get_first_name(), "Gabrielle");
        checkEquals($client->get_SSN(), SSN);
    }

    $res = remove_client(ID);
    if ($res == null)
        echo 'Retrieve failed</br>';
}

// tests the retrieve_clients_by_name() function in dbPersons.php
function testRetrieve_client_by_name() {
  $client = new Client("Gabrielle", "Booth", SSN, "14 Way St", "Harpswell, ME, 04079", PHONE, "212-899-3434", "Sam Booth", "212-455-9999","Jan 5, 2005",9,"meds","notes");

    echo 'will test retrieve_client_by_name </br>';
    $result = add_client($client);
    echo 'result is ' . $result.'</br>';
    if ($result)
        echo "client inserted </br>";
    else
        echo "client not inserted</br>";

    echo "test retrieve_clients_by_name</br>";
    $personList = retrieve_client_by_name("Gabrielle Booth");
    if ($personList == null)
        echo 'Retrieve failed</br>';
    else {
        checkEquals($personList[0]->get_first_name(), "Gabrielle");
        checkEquals($personList[0]->get_SSN(), SSN);
    }

    $res = remove_client(ID);
    if ($res == null)
        echo 'Retrieve failed</br>';
}
/*
function testGetOnlyThose_dbClients()
{
    $client = new Client("Gabrielle", "Booth", SSN, "14 Way St", "Harpswell, ME, 04079", PHONE, "212-899-3434", "Sam Booth", "212-455-9999","Jan 5, 2005",9,"meds","notes");

    echo 'will test getOnlyThose_dbClients </br>';
    $result = add_client($client);
    echo 'result is ' . $result.'</br>';
    if ($result)
        echo "client inserted </br>";
    else
        echo "client not inserted</br>";


    $personList =  getonlythose_dbClients("", "Gabrielle", "Booth");
    if ($personList == null)
        echo 'getonlythose_dbClients returned no records</br>';
    else {
        checkEquals($personList[0]->get_first_name(), "Gabrielle");
        checkEquals($personList[0]->get_SSN(), SSN);
    }

    $res = remove_client(ID);
    if ($res == null)
        echo 'Remove failed</br>';
}
*/
function testRetrieve_client_by_ssn() {
  $client = new Client("Gabrielle", "Booth", SSN, "14 Way St", "Harpswell, ME, 04079", PHONE, "212-899-3434", "Sam Booth", "212-455-9999","Jan 5, 2005",9,"meds","notes");

    echo 'will test retrieve_client_by_name </br>';
    $result = add_client($client);
    echo 'result is ' . $result.'</br>';
    if ($result)
        echo "client inserted </br>";
    else
        echo "client not inserted</br>";

    echo "test retrieve_clients_by_ssn</br>";
    $personList = retrieve_client_by_ssn("Gabrielle Booth");
    if ($personList == null)
        echo 'Retrieve failed</br>';
    else {
        checkEquals($personList[0]->get_SSN(), SSN);
    }

    $res = remove_client(ID);
    if ($res == null)
        echo 'Retrieve failed</br>';
}

function testRetrieve_client_by_status() {
  $client = new Client("Gabrielle", "Booth", SSN, "14 Way St", "Harpswell, ME, 04079", PHONE, "212-899-3434","status", "Sam Booth", "212-455-9999","Jan 5, 2005",9,"meds","notes");

    echo 'will test retrieve_client_by_name </br>';
    $result = add_client($client);
    echo 'result is ' . $result.'</br>';
    if ($result)
        echo "client inserted </br>";
    else
        echo "client not inserted</br>";

    echo "test retrieve_clients_by_ssn</br>";
    $personList = retrieve_client_by_status("status");
    if ($personList == null)
        echo 'Retrieve failed</br>';
    else {
        checkEquals($personList[0]->get_status(), status);
    }

    $res = remove_client(ID);
    if ($res == null)
        echo 'Retrieve failed</br>';
}

